#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>

#include "proto.h"

int main(int argc, char *argv[])
{

	int sockfd;
	struct msg_st sbuf;
	struct sockaddr_in raddr;

	if(argc < 2){
		fprintf(stderr, "Usage...\n");
		exit(1);
	}

	sockfd = socket(AF_INET, SOCK_DGRAM, 0);
	if(sockfd < 0){
		perror("socket()");
		exit(1);
	}

	strcpy(sbuf.name,"Tom");
	sbuf.math = htonl(rand()%100);
	sbuf.chinese = htonl(rand()%100);

	raddr.sin_family = AF_INET;
	raddr.sin_port = htons(atoi(RECPORT));
	inet_pton(AF_INET, argv[1], &raddr.sin_addr);

	if(sendto(sockfd, &sbuf, sizeof(sbuf), 0, (void *)&raddr, sizeof(raddr)) < 0){
		perror("sendto()");
		exit(1);
	}

	puts("OK!");

	close(sockfd);

	exit(1);
}
